home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / C / Code Resources / Progress CDEF 1.3.1 / Progress.c < prev    next >
C/C++ Source or Header  |  1996-07-07  |  3KB  |  146 lines

  1. /* ----------------------------------------------------------------------
  2.  
  3.     Progress CDEF
  4.     version 1.3.1
  5.     
  6.     Written by: Paul Celestin
  7.     
  8.     Copyright © 1993-1996 Celestin Company, Inc.
  9.     
  10.     This CDEF displays a very simple progress thermometer.
  11.     
  12.     930927 - 1.0.0 - initial release
  13.     931012 - 1.0.1 - bug fixes
  14.     940320 - 1.0.2 - more bug fixes
  15.     951215 - 1.3.0 - updated for CW7
  16.     960704 - 1.3.1 - updated for CW9
  17.  
  18. ---------------------------------------------------------------------- */
  19.  
  20. /* ----------------------------------------------------------------------
  21. prototypes
  22. ---------------------------------------------------------------------- */
  23. pascal long main(short, ControlHandle, short, long);
  24. void drawIt(ControlHandle, short);
  25.  
  26.  
  27. /* ----------------------------------------------------------------------
  28. main
  29. ---------------------------------------------------------------------- */
  30. pascal long main(short variation, ControlHandle theControl, short message, long param)
  31. {
  32.     long    returnValue = 0L;
  33.     char    state = HGetState((Handle)theControl);
  34.     Str255    copyright = "\pCopyright © 1993-1996 Celestin Company, Inc.";
  35.  
  36.     switch(message)
  37.     {
  38.         case drawCntl:
  39.             drawIt(theControl,variation);
  40.         case testCntl:
  41.             break;
  42.         case calcCRgns:
  43.             break;
  44.           case initCntl:
  45.               break;
  46.         case dispCntl:
  47.             break;
  48.         case posCntl:
  49.             break;
  50.         case thumbCntl:
  51.             break;
  52.         case dragCntl:
  53.             break;
  54.         case autoTrack:
  55.             break;
  56.         case calcCntlRgn:
  57.             break;
  58.         case calcThumbRgn:
  59.             break;
  60.         default:
  61.             break;
  62.     }
  63.  
  64.     HSetState((Handle)theControl,state);
  65.  
  66.     return(returnValue);                /* tell them what happened */
  67. }
  68.  
  69.  
  70. /* ----------------------------------------------------------------------
  71. drawIt - here is where we actually draw the control
  72. ---------------------------------------------------------------------- */
  73. void drawIt(ControlHandle control, short variation)
  74.  
  75. {
  76.     Rect             myRect;
  77.     PenState        oldPenState;
  78.     int                myValue = GetCtlValue(control),
  79.                     myMax = GetCtlMax(control),
  80.                     myMin = GetCtlMin(control),
  81.                     myColor,
  82.                     width = 0,
  83.                     range = 100;
  84.  
  85.     if (!(*control)->contrlVis)                /* if not visible, do nothing */
  86.         return;
  87.  
  88.     GetPenState(&oldPenState);                /* save off current environment */
  89.  
  90.     myRect = (*control)->contrlRect;        /* define our control rect */
  91.     
  92.     PenNormal();                            /* make pen normal */
  93.     
  94.     FrameRect(&myRect);                        /* draw border around the control */
  95.     InsetRect(&myRect,1,1);
  96.  
  97.     ForeColor(whiteColor);
  98.     BackColor(whiteColor);
  99.     PaintRect(&myRect);
  100.  
  101.     width = myRect.right - myRect.left;        /* width in pixels of the control */
  102.     range = myMax - myMin;
  103.     
  104.     if (range < 10) range = 10;                /* to deal with screwy ranges */
  105.     
  106.     myRect.right = myRect.left + (myValue * width) / range;
  107.     
  108.     switch (GetCRefCon(control))
  109.     {
  110.         case 1:
  111.             myColor = redColor;
  112.             break;
  113.         case 2:
  114.             myColor = greenColor;
  115.             break;
  116.         case 3:
  117.             myColor = blueColor;
  118.             break;
  119.         case 4:
  120.             myColor = cyanColor;
  121.             break;
  122.         case 5:
  123.             myColor = magentaColor;
  124.             break;
  125.         case 6:
  126.             myColor = yellowColor;
  127.             break;
  128.         case 7:
  129.             myColor = whiteColor;
  130.             break;
  131.         default:
  132.             myColor = blackColor;
  133.             break;
  134.     }
  135.     
  136.     ForeColor(myColor);
  137.     BackColor(myColor);
  138.     PaintRect(&myRect);
  139.  
  140.     ForeColor(blackColor);
  141.     BackColor(whiteColor);
  142.     SetPenState(&oldPenState);                /* restore the original environment */
  143.     
  144.     return;                                    /* we are done drawing */
  145. }
  146.